home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / pctv4n_1.zip / CONCEN.TXT < prev    next >
Text File  |  1993-06-10  |  5KB  |  202 lines

  1. ' Listing 2 - Concen.Frm
  2. Const MAX_MATCH = 20
  3.  
  4. Dim CrLf As String
  5.  
  6. Dim PiecesLoaded As Integer
  7. Dim CurrentPlayer As Integer
  8. Dim NumShown As Integer
  9. Dim Piece1 As Integer
  10. Dim Piece2 As Integer
  11. Dim PlayingGame As Integer
  12. Dim MatchesMade As Integer
  13.  
  14. Sub NewCmd_Click ()
  15. ReDim TrackUsed(1 To 20) As Integer
  16. Dim Selection As Integer, PicSelected As Integer
  17. Dim i As Integer
  18.  
  19.     ' Initialize game variables
  20.     InitPlayerRecs
  21.     MousePointer = HOURGLASS
  22.    
  23.     ' Load the game pieces if not already done.
  24.     If Not PiecesLoaded% Then
  25.         For i% = 1 To 39
  26.             Load btnGamePiece(i%)
  27.             InitGamePiece btnGamePiece(i%)
  28.         Next i%
  29.         PiecesLoaded% = TRUE
  30.     End If
  31.     
  32.     Piece1% = -1
  33.     Piece2% = -1
  34.     MatchesMade% = 0
  35.     PlayingGame = TRUE
  36.     
  37.     ' Shuffle the pieces
  38.     Randomize Timer
  39.     For i% = 0 To 39
  40.         PicSelected% = FALSE
  41.         Do
  42.             Selection% = Int(Rnd(1) * 20) + 1
  43.             If TrackUsed(Selection%) < 2 Then
  44.                 PicSelected% = TRUE
  45.                 TrackUsed(Selection%) = TrackUsed(Selection%) + 1
  46.                 SetPic btnGamePiece(i%), Selection%
  47.             End If
  48.         Loop Until PicSelected%
  49.     Next i%
  50.  
  51.     MousePointer = DEFAULT
  52.     MsgBox "Ready to start game.", MB_ICONINFORMATION, "New Game"
  53. End Sub
  54.  
  55.  
  56. Sub ExitCmd_Click ()
  57.     End
  58. End Sub
  59.  
  60. Sub Form_Load ()
  61.     CrLf$ = Chr$(13) + Chr$(10) ' Initialize CrLf$
  62. End Sub
  63.  
  64. Sub btnGamePiece_Click (Index As Integer)
  65. Dim NewScore As Integer
  66.  
  67.     If Index = Piece1% Then
  68.         btnGamePiece(Index).Frame = 2
  69.         btnGamePiece(Index).Value = 2
  70.         Exit Sub
  71.     End If
  72.  
  73.     NumShown% = NumShown% + 1
  74.  
  75.     If PlayingGame Then
  76.         Select Case NumShown%
  77.             Case 1
  78.                 Piece1% = Index
  79.             Case 2
  80.                 Piece2% = Index
  81.                 If btnGamePiece(Piece1%).Tag = btnGamePiece(Piece2%).Tag Then
  82.                     MessageBeep (MB_ICONINFORMATION)
  83.                     MsgBox "You made a match!", MB_ICONINFORMATION, "A Match!"
  84.                     btnGamePiece(Piece1%).Visible = FALSE
  85.                     btnGamePiece(Piece2%).Visible = FALSE
  86.                     NumShown% = 0
  87.                     Piece1% = -1
  88.                     Piece2% = -1
  89.                     NewScore% = Players(CurrentPlayer).Score
  90.                     NewScore% = NewScore% + 1
  91.                     Players(CurrentPlayer).Score = NewScore%
  92.                     PlayerScore(CurrentPlayer - 1).Caption = Str$(NewScore%)
  93.                     MatchesMade% = MatchesMade% + 1
  94.                 Else
  95.                     Timer1.Interval = 3000 / Players(CurrentPlayer).Level
  96.                     Timer1.Enabled = TRUE
  97.                 End If
  98.             Case 3
  99.                 btnGamePiece(Index).Value = 1
  100.                 btnGamePiece(Index).Frame = 1
  101.                 NumShown% = 2
  102.         End Select
  103.     Else
  104.         MsgBox "Start a new game first!", MB_ICONEXCLAMATION, "Error"
  105.     End If
  106.     If MatchesMade% >= MAX_MATCH Then
  107.         AnnounceWinner
  108.     End If
  109. End Sub
  110.  
  111. Sub Timer1_Timer ()
  112.     btnGamePiece(Piece1%).Value = 1
  113.     btnGamePiece(Piece2%).Value = 1
  114.     NumShown% = 0
  115.     Piece1% = -1
  116.     Piece2% = -1
  117.     Timer1.Enabled = FALSE
  118.     If CurrentPlayer = 1 Then
  119.         PlayerName(0).BackColor = QBColor(15)
  120.         PlayerName(1).BackColor = QBColor(7)
  121.         CurrentPlayer = 2
  122.     Else
  123.         PlayerName(1).BackColor = QBColor(15)
  124.         PlayerName(0).BackColor = QBColor(7)
  125.         CurrentPlayer = 1
  126.     End If
  127. End Sub
  128.  
  129. Sub AnnounceWinner ()
  130. Dim Msg As String, Title As String
  131.  
  132.     If Players(1).Score > Players(2).Score Then
  133.         Msg$ = Players(1).Name + " is the winner!"
  134.         Title$ = "Congratulations!"
  135.     ElseIf Players(1).Score < Players(2).Score Then
  136.         Msg$ = Players(2).Name + " is the winner!"
  137.         Title$ = "Congratulations!"
  138.     Else
  139.         Msg$ = "The game was tied!"
  140.         Title$ = "No Winner"
  141.     End If
  142.     MsgBox Msg$, MB_ICONEXCLAMATION, Title$
  143.     PlayingGame = FALSE
  144. End Sub
  145.  
  146. Sub InitPlayerRecs ()
  147. Dim i As Integer
  148.  
  149.     For i% = 1 To 2
  150.         Players(i%).Level = 1
  151.     Next i%
  152.     PlayerInfoForm.Show MODAL
  153.     Unload PlayerInfoForm
  154.     CurrentPlayer = 1
  155.     For i% = 1 To 2
  156.         PlayerName(i% - 1).Caption = Players(i%).Name
  157.     Next i%
  158.     PlayerName(CurrentPlayer - 1).BackColor = QBColor(7)
  159. End Sub
  160.  
  161. Sub SetPic (PicBox As Control, PicNum As Integer)
  162.     PicBox.Frame = 2
  163.     PicSet.Frame = PicNum%
  164.     PicBox.Picture = PicSet.Picture
  165.     PicBox.Tag = Str$(PicNum%)
  166.     PicBox.Frame = 1
  167.     PicBox.Value = 1
  168.     PicBox.Enabled = TRUE
  169.     PicBox.Visible = TRUE
  170. End Sub
  171.  
  172. Sub InitGamePiece (Piece As Control)
  173. Static X, Y
  174.  
  175.     ' Make sure x and y are only initialized the
  176.     ' first time the Sub gets called.
  177.     If X = 0 Then
  178.         X = 720
  179.         Y = 120
  180.     End If
  181.     Piece.Left = X
  182.     Piece.Top = Y
  183.     ' Piece.Picture = Source.Picture
  184.     X = X + 600
  185.     If X > 5520 Then
  186.         X = 120
  187.         Y = Y + 600
  188.     End If
  189. End Sub
  190.  
  191. Sub AboutCmd_Click ()
  192.     AboutBox.Show MODAL
  193.     Unload AboutBox
  194. End Sub
  195.  
  196. Sub Form_Unload (Cancel As Integer)
  197.     For i% = 1 To 39
  198.         Unload btnGamePiece(i%)
  199.     Next i%
  200. End Sub
  201.  
  202.